#ifndef __BLDC_COMMUTATION_H
#define __BLDC_COMMUTATION_H

// 引脚定义
#define ENA_Pin         	GPIO_PIN_8
#define ENA_GPIO_Port   	GPIOA
#define ENB_Pin         	GPIO_PIN_9
#define ENB_GPIO_Port   	GPIOA
#define ENC_Pin         	GPIO_PIN_10
#define ENC_GPIO_Port   	GPIOA
#define PWMA_Pin        	GPIO_PIN_13
#define PWMA_GPIO_Port  	GPIOB
#define PWMB_Pin        	GPIO_PIN_14
#define PWMB_GPIO_Port  	GPIOB
#define PWMC_Pin        	GPIO_PIN_15
#define PWMC_GPIO_Port  	GPIOB
#define nSLEEP_Pin      	GPIO_PIN_11
#define nSLEEP_GPIO_Port 	GPIOB
#define nFAULT_Pin      	GPIO_PIN_9  // 假设，需确认
#define nFAULT_GPIO_Port 	GPIOB

typedef struct {
  uint8_t pwm_a; // 0: Low, 1: PWM, 2: Hi-Z
  uint8_t pwm_b;
  uint8_t pwm_c;
  uint8_t ena;
  uint8_t enb;
  uint8_t enc;
} CommutationStep;

// 电机状态枚举
typedef enum {
    MOTOR_STOP,
    MOTOR_CLOCKWISE,
    MOTOR_COUNTERCLOCKWISE
} MotorState;

extern void Set_PWM_State(uint8_t pwm_state, TIM_HandleTypeDef *htim, uint32_t channel, uint16_t duty_percent, uint8_t is_complementary);
extern void SetCommutationStep(uint8_t step, uint16_t duty_percent);
extern void SixStepCommutationTest(uint16_t duty_percent, uint32_t step_delay_ms);
extern void ReadHallAndDetermineStep(void);
extern void ReadHallAndDetermineStep_Demo(void);

#endif